package com.robot.mq.listener;

import com.alibaba.fastjson.JSON;
import com.robot.mq.handler.AliSmsHandler;
import entity.Sms;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author lin
 */
@Component
@RabbitListener(queues = "sms")
public class SmsListener {
    @Value("${spring.profiles.active}")
    private String env;

    private final Logger logger= LoggerFactory.getLogger(this.getClass());

    @RabbitHandler
    public void execute(String smsStr){
        logger.info(smsStr);
        Sms sms= JSON.parseObject(smsStr,Sms.class);
        String prod = "prod";
        if(prod.equals(env)){
            AliSmsHandler.send(sms);
        }

    }
}

